<template>
    <div class="pagestyle">
        <list_controller ref="zujianname" :options="state.optionsList" pageName="" @deleteBtn="deleteBtn"
            @tabChange="tabChange" :addBtnMul="false" :delBtnMul="true" :editBtnMul="false"
            :tabName="state.tabNameData">
        </list_controller>
    </div>
</template>
<script setup>
    import list_controller from "@/components/commonCom/list_controller";
    import {
        computed,
        reactive
    } from "vue";
    import {
        table_headers
    } from '@/components/commonCom/table_headers';
    import axios from "@/utils/request"
    import {
        getchildIndex,
        getsensorName,
        getunit,
        fileupload,
        getchildIndexadd,
        getsensorNameadd
    } from '@/api/config'
    import usePagesStore from '@/store/modules/pages'
    const {
        proxy
    } = getCurrentInstance();
    const store = usePagesStore()
    components: {
        list_controller
    }
    let state = reactive({
        tabNameData: '历史分站',
        optionsList: {},
        options: {
            tabList: [{
                    tabIndex: 1,
                    name: '历史分站'
                }, {
                    tabIndex: 2,
                    name: '历史测点'
                }, {
                    tabIndex: 3,
                    name: '历史虚拟测点'
                },
                {
                    tabIndex: 4,
                    name: '历史电源'
                }
            ],
            tableheads: computed(() => table_headers.sensorSimulate),
            queryList: {
                dropdownUrl: '',
                curdList: [{
                    name: '查看',
                    type: 'lookBtn'
                }, {
                    name: '删除',
                    type: 'deleteBtn'
                }],
                querys: [{
                    field: 'sensorName',
                    title: '关键词搜索',
                    type: 'input',
                    binddata: ''
                }],
                queryMap: new Map([])
            },
            dataUrl: '/substation/type/search',
            delUrl: '/sensor/simulate/delete',
            descUrl: '/sensor/simulate/detail?id=',
        },
        options1: {
            tabList: [{
                    tabIndex: 1,
                    name: '历史分站'
                }, {
                    tabIndex: 2,
                    name: '历史测点'
                }, {
                    tabIndex: 3,
                    name: '历史虚拟测点'
                },
                {
                    tabIndex: 4,
                    name: '历史电源'
                }
            ],
            tableheads: computed(() => table_headers.sensorSwitch),
            queryList: {
                dropdownUrl: '',
                curdList: [{
                    name: '查看',
                    type: 'lookBtn'
                }, {
                    name: '删除',
                    type: 'deleteBtn'
                }],
                querys: [{
                    field: 'sensorName',
                    title: '关键词搜索',
                    type: 'input',
                    binddata: ''
                }],
                queryMap: new Map([

                ])
            },
            dataUrl: '/sensor/switch/list',
            delUrl: '/sensor/simulate/delete',
            descUrl: '/sensor/switch/detail?id=',
        },
        options2: {
            tabList: [{
                    tabIndex: 1,
                    name: '历史分站'
                }, {
                    tabIndex: 2,
                    name: '历史测点'
                }, {
                    tabIndex: 3,
                    name: '历史虚拟测点'
                },
                {
                    tabIndex: 4,
                    name: '历史电源'
                }
            ],
            tableheads: computed(() => table_headers.sensorAdd),
            queryList: {
                dropdownUrl: '',
                curdList: [{
                    name: '查看',
                    type: 'lookBtn'
                }, {
                    name: '删除',
                    type: 'deleteBtn'
                }],
                querys: [{
                    field: 'sensorName',
                    title: '关键词搜索',
                    type: 'input',
                    binddata: ''
                }],
                queryMap: new Map([

                ])
            },
            dataUrl: '/sensor/add/list',
            delUrl: '/sensor/simulate/delete',
            descUrl: '/sensor/add/detail?id=',
        },
    })


    function deleteBtn(row) {
        let ids = []
        if (row != 'mul') {
            ids = [row.id]
        } else {
            if (store.records.length > 0) {
                ids = store.records.map(item => {
                    return item.id
                })
            } else {
                proxy.$modal.msgSuccess('请先勾选所要删除数据!');
            }
        }
        if (ids.length > 0) {
            axios.post(state.options.delUrl, ids).then(res => {
                if (res.code == 200) {
                    proxy.$refs['zujianname'].getData()
                    proxy.$modal.msgSuccess(res.msg);
                    store.records = []
                }
            })
        }

    }

    function tabChange(val) {
        state.tabNameData = val
    }
    state.optionsList = state.options
</script>
<style scoped lang="scss">

</style>